﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;

namespace FasterWPF
{
    public class TextBoxArgs
    {
    }

    public class TextBoxBaseScrollViewerStrategy:  FasterWPF.IScrollViewerStrategy
    {        
        public ScrollViewer GetScrollViewer(object chain)
        {
            TextBoxBase lbx = (TextBoxBase)chain;
            var builtCheck = lbx.ApplyTemplate();
            Microsoft.Windows.Themes.ListBoxChrome bd = (Microsoft.Windows.Themes.ListBoxChrome)lbx.Template.FindName("Bd", lbx);

            ScrollViewer svw = bd.Child.Cast<ScrollViewer>();

            return svw;
        }

        public T GetParentContainerFromScrollViewerThumb<T>(System.Windows.Controls.Primitives.Thumb myThumb)
        {
            T source = ((Microsoft.Windows.Themes.ListBoxChrome)((ScrollViewer)
                ((Grid)
                ((ScrollBar)myThumb.TemplatedParent).Parent).TemplatedParent
                ).Parent).TemplatedParent.Cast<T>();
            return source;
        }
    }
}
